package com.wu.dms.controller;

import com.wu.common.convertion.result.Result;
import com.wu.common.convertion.result.Results;
import com.wu.constant.Enum.ResourceTypeAndNameEnum;
import com.wu.dms.dao.vo.CommentPageVo;
import com.wu.dms.dao.mapper.CommentMapper;
import com.wu.dms.dto.req.CommentLikeUpdateReq;
import com.wu.dms.dto.resp.PageResp;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EDY
 */
@RestController
@RequiredArgsConstructor
public class CommentController {
    private final CommentMapper commentMapper;

    // 提交评论
    @PostMapping("/comment/add")
    public Result<Void> addComment() {
        return Results.success("添加评论成功");
    }

    // 删除评论
    @GetMapping("/comment/delete")
    public Result<Void> deleteComment(@RequestParam Long id) {
        commentMapper.deleteComment(id);
        return Results.success("删除评论成功");
    }


    // 获得指定歌单 ID 的评论列表
    @GetMapping("/comment/queryInPage")
    public Result<PageResp> commentOfSongListIdOrSongId(@RequestParam(required = false) Integer resourceType, @RequestParam String searchWord, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize
    , @RequestParam String startDate, @RequestParam String endDate) {
        List<CommentPageVo> data = commentMapper.getCommentInPage(resourceType,searchWord, pageNum, pageSize, startDate, endDate);
        for (CommentPageVo datum : data) {
            datum.setResourceType(ResourceTypeAndNameEnum.getNameByType(datum.getResourceType()));
        }
        long count = commentMapper.countCommentInPage(resourceType,searchWord,startDate,endDate);
        PageResp result = new PageResp();
        result.setData(data);
        result.setTotal(count);
        return Results.success(result);
    }
    @PostMapping("/comment/like/update")
    public Result<Void> commentOfLikeUpdate(@RequestBody CommentLikeUpdateReq commentLikeUpdateReq) {
        commentMapper.updateCommentLikeUp(commentLikeUpdateReq.getId(),commentLikeUpdateReq.getUp());
        return Results.success("数据更新成功");
    }

}
